package com.px.controller;


import com.px.dto.CommentDto;
import com.px.pojo.*;
import com.px.service.*;
import com.px.vo.CommentReq;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class GoodsControllerProvider {

    @Resource
    private CollectionServiceProvider collectionServiceProvider;
    @Resource
    private CommentServiceProvider commentServiceProvider;

    @Resource
    private CommodityServiceProvider commodityServiceProvider;
    @Resource
    private CommodityTempStockDaoService commodityTempStockDaoService;

    @Resource
    private DicServiceProvider dicServiceProvider;

    @PostMapping("provider/goods/findCommodityTempStock")
    public boolean findCommodityTempStock(@RequestBody ShCommodityTempStock shCommodityTempStock)throws Exception {
        return commodityTempStockDaoService.findCommodityTempStock(shCommodityTempStock);
    }
    @PostMapping("/provider/goods/getByDicId")
    public List<ShCommodity> getByDicId(@RequestParam Integer id)throws Exception {
        return commodityServiceProvider.findCommodityByDic(id);
    }
    @PostMapping("/provider/goods/getByDicTwoId")
    public List<ShCommodity> getByDicTwoId(@RequestParam Integer dicId)throws Exception {
        return commodityServiceProvider.findByDicTwoId(dicId);
    }
    @PostMapping("/provider/goods/getTypeNameByDicId")
    public List<ShDic> getTypeNameByDicId(@RequestParam Integer dicId)throws Exception {
        return dicServiceProvider.getTypeNameByDicId(dicId);
    }

    @PostMapping("/provider/goods/insertComment")
    public boolean insertComment(@RequestBody ShComment comment)throws Exception {
        return commentServiceProvider.insertComment(comment);
    }
    @PostMapping("/provider/goods/getCartoonComments")
    public List<CommentDto> getCartoonComments(CommentReq commentReq)throws Exception {
        return commentServiceProvider.getCartoonComments(commentReq);
    }

    @PostMapping("/provider/goods/findCommentById")
    public ShCommodity findCommentById(@RequestParam Integer id)throws Exception {
        return commodityServiceProvider.findCommentById(id);
    }


    @PostMapping("/provider/goods/insertCollection")
    public boolean insertCollection(@RequestBody ShCollection collection)throws Exception {
        return collectionServiceProvider.insertCollection(collection);
    }
    /**
     * 根据商品id查询购物车是否添加过该商品
     * @param commodityId
     * @return
     * @throws Exception
     */
    @PostMapping("/provider/goods/selectCollectionByCommodityId")
    public ShCollection selectCollectionByCommodityId(@RequestParam Integer commodityId)throws Exception {
        return collectionServiceProvider.findCollection(commodityId);
    }
    /**
     * 购物车相同商品进行累加 更新操作
     * @param collection
     * @return
     * @throws Exception
     */
    @PostMapping("/provider/goods/updateCollectionByCommodityId")
    public boolean updateCollectionByCommodityId(@RequestBody ShCollection collection)throws Exception {
        return collectionServiceProvider.updateCollection(collection);
    }


    @PostMapping("/provider/goods/findDelShopping")
    public boolean findDelShopping(@RequestParam Integer id)throws Exception {
        return collectionServiceProvider.deleteById(id);
    }

}
